<?php

namespace app\middleware;

use app\facade\Token;
use app\model\user\UserModel;

class PowerCheck
{
    public function handle($request, \Closure $next, $power)
    {
        if (cookie('token') == '') {
            return json(['code'=>-1,'msg'=>'请先登录']);
        }

        $uid = Token::getUid();
        $group = UserModel::getGroup($uid);


        if (($group & $power) == $group) {
            return $next($request);
        } else {
            return json(["msg"=>"权限不足！"]);
        }

    }
}